package indi.zn.commons.serialno.plus;

import java.util.Calendar;
import java.util.Date;

import indi.zn.commons.serialno.SeqPersistenceService;


class MonthSequence  extends indi.zn.commons.serialno.Sequence{
	
	
	Integer beforeMonth;

	public MonthSequence(String name,Long begin, Integer step, Long range, boolean cycle ,SeqPersistenceService  persister) {
	
		super(name, begin, step, range, cycle, persister,null);
	}

	
	public synchronized  String getNext() {
		
		Calendar cal = Calendar.getInstance();
		
		if(beforeMonth==null) {
		beforeMonth = cal.get(Calendar.MONTH )+1;
		}
		
		
		if(beforeMonth!=(cal.get(Calendar.MONTH )+1)) {
			beforeMonth=cal.get(Calendar.MONTH )+1;
			super.reset();
		}
		
		 return super.getNext();
		
	}
	
	
	public static void main(String[] args) throws InterruptedException {
		
		MonthSequence ms=new MonthSequence("test",0l,1,10000l,true,null);

	while(true) {
	
		Thread.currentThread().sleep(2000);
		
	   String str=ms.getNext();
	   
	   System.out.println(new Date()+" / "+str);
	}
	   	
	}
	
}
